import { reactive } from "vue"
import request from '@/utils/request'
import {listBaseConfig} from '@/api/config/param'
export const operationItem = reactive({
	defaultSearch: true,//默认搜索按钮
	defaultRefresh: true,//默认重置按钮
	customTableHeader: false,//
	SearchItem: [
		{
			code: "courseTypeName",
			name: "课程名称",
			type: 'input',
		},
	],
	menuArray: [
		{
			show: true,
			code: 'add',
			type: 'primary',
			text: '新增',
		},
	]
})

export const tableItem = reactive({
    select: false,//多选框
    index: false,//顺序
    loading: false,
    expandAll: false,//树形默认展开
    tree: false,//树形
	align: 'center',
    column: [
        {
            align: 'center',
            label: '课程名称',
            prop: 'courseTypeName',
        },
			{
				align: 'center',
				label: '所在地区',
				prop: 'provinceNames',
			},

		{
			align: 'center',
			label: '内容',
			tooltip: true,
			htmlContent: row => {
				let content = ''
				let arr = JSON.parse(row.value)
				if(arr) {
					arr.map(item => {
						content = content + item.desc + '：' + item.content + '；'
					})
				}
				return `<span>${content}</span>`

				// return `<span>${'客服：' + row.extra}</span>`
			},
		},
		{
			align: 'center',
			label: '状态',
			prop: '',
			htmlContent: row => {
				return `<span>${row.disableFlag == 1? '禁用' : '启用'}</span>`
			},
		},
        {
            label: '操作',
            prop: 'action',
        }

    ],
    pageInfo: {
        pagesClose: true,
        request: {
            "name": "",
            "parentId": "",
        },
        url: '',//分页路由，不传的话需要传入自定义的分页函数paging 传入时定义的分页函数paging会失效
        method: '',//分页请求方法，不传默认为POST
        // 分页函数paging
        paging: function () {
			let code = sessionStorage.getItem('code')
			let paramId = sessionStorage.getItem('paramId')
			tableItem.pageInfo.request.code = code
			tableItem.pageInfo.request.parentId = paramId
			listBaseConfig(tableItem.pageInfo.request).then(res => {
				tableItem.tableData.data = res.rows
				tableItem.tableData.total = res.total
			}).catch(() => {});
			//
			// for (const key in tableItem.pageInfo.request) {
			// 	!tableItem.pageInfo.request[key] ? tableItem.pageInfo.request[key] = null : ''
			// }
			// if (!tableItem.pageInfo.request) { return }
			// tableItem.loading = true
        }
    },
    // 分页数据 自定义分页函数paging时需要把值赋给tableData
    tableData: {
        total: '',//分页总计
        // 分页数据
        data: []
    },
    // 操作栏按钮
    btnArray: [
		{
			type: 'primary',//类别 摈弃了text
			label: '修改',
			code: 'edit',
		},
		{
			type: 'primary',//类别 摈弃了text
			label: '启用',
			code: 'able',
			showFunction: (row)=>{
				return row.disableFlag == 1;
			},
		},
		{
			type: 'danger',//类别 摈弃了text
			label: '禁用',
			code: 'disable',
			showFunction: (row)=>{
				return row.disableFlag == 0;
			},
		},
		{
			type: 'danger',//类别 摈弃了text
			label: '删除',
			code: 'del',
		},
    ],
    moreBtnArrayText: '',//自定义更多标题 默认为更多
    moreBtnArray: [],
    // 选择框触发
    selectChange: function (row) {},
}
)
